package com.xiangban.controller;

import com.alibaba.fastjson.JSON;
import com.xiangban.model.dto.SmsParameterDto;
import com.xiangban.model.dto.TSystemDto;
import com.xiangban.model.res.ApiResult;
import com.xiangban.service.MessageService;
import com.xiangban.utils.ALiYunSms;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
@RequestMapping("/send")
@Slf4j
public class SmsController {
 @Autowired
    private MessageService messageService;
    @RequestMapping("/sendSms")
    public ApiResult<Object> sendSms(@RequestBody SmsParameterDto smsParameterDto){
        log.info(JSON.toJSONString(smsParameterDto));
        log.info(JSON.toJSONString(smsParameterDto.getSignName()));
        ALiYunSms.sendSms(smsParameterDto.getSignName(),smsParameterDto.getSmsTemplate(), smsParameterDto.getMobile(), smsParameterDto.getTemplateParam());
        return ApiResult.newSuccess();
    }
   @PostMapping("/sendByOpenId")
    public ApiResult<Object> sendByOpenId(@RequestBody TSystemDto tSystemDto){//微信推送模板

        return ApiResult.newSuccess(messageService.sendByOpenId(tSystemDto));
   }



}
